home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c++
- Subject: Re: Passing a pointer to a class function
- Date: Thu, 18 Jan 1996 13:30:54 GMT
- Organization: Netcom
- Message-ID: <30fe4acc.66601856@nntp.ix.netcom.com>
- References: <Pine.SUN.3.91.960117160141.13519A-100000@sasabe.acms.arizona.edu>
- NNTP-Posting-Host: ix-dc8-24.ix.netcom.com
- X-NETCOM-Date: Thu Jan 18 5:30:38 AM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- Kenton White <jwhite@sasabe.acms.arizona.edu> wrote:
-
- >
- > I have a library subroutine that takes as an argument a pointer to a
- > function. I want to pass instead a pointer to a class function. The
- > class looks like this:
- >
- > class device {
- >
- > // ...
- >
- > public:
- >
- > //...
- > void derivs(float, complex*, complex*)
- > };
- >
- > The subroutine expects a pointer to a function like this:
- >
- > rk(void (*)(float, void*, void*))
- >
- > I pass the class function like this:
- >
- > device laser;
- > rk(void (*)(float,void*, void*))laser.derivs;
- >
- > When it compiles it gives me an anachronism warning and then crashes
- > with a memory fault on execution. I have developed a temporary fix by
- > declaring a seperate function in the main program called derivs that
- > calls the class function derivs. This works but is silly. Is there a
- > way to pass the pointer to the class function?
-
- No. Pointer to function and pointer to member function are different
- types and cannot be converted to one another.
-
- The problem is that there is no mechanism to tell the user of a
- pointer to function that it's really a pointer to member function and
- must be called with an appropriate class object.
-
- Michael M Rubenstein
-